package com.lvyou.ctrls;


import com.lvyou.model.Result;
import com.lvyou.service.RegSrvImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
public class RegCtrl {
    @Resource
    private RegSrvImpl srv;
    @RequestMapping("/reg")
    public ModelAndView reg(String password, String phone) {
        ModelAndView mv=new ModelAndView();
        if(phone==null||"".equals(phone)){
            mv.setViewName("redirect:/regFails.jsp?error=2");
            return mv;
        }
        if(password==null||"".equals(password)){
            mv.setViewName("redirect:/regFails.jsp?error=1");
            return mv;
        }
        Result res=srv.reg(password,phone);
        if(res.getCode()==0){
            mv.setViewName("index");
        }else{
            mv.setViewName("redirect:/regFails.jsp?error=3");
        }
        return mv;
    }
}